﻿using System;
using System.Collections.Generic;

using Hammock.Web;

namespace TMWS
{
	using Models;

	/// <summary>
	/// Player service
	/// </summary>
	public class PlayerService : ServiceBase
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="PlayerService"/>
		/// </summary>
		/// <param name="username">API username</param>
		/// <param name="password">APU password</param>
		public PlayerService(string username, string password)
			: base(username, password, false)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="PlayerService"/>
		/// </summary>
		/// <param name="username">API username</param>
		/// <param name="password">APU password</param>
		/// <param name="enableLogging">Enable logging</param>
		/// <param name="logDirectory">Directory to store logs</param>
		public PlayerService(string username, string password, bool enableLogging, string logDirectory)
			: base(username, password, enableLogging, logDirectory)
		{
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Gets information about the specified player
		/// </summary>
		/// <param name="login">Player login</param>
		/// <returns>Player information</returns>
		public TrackManiaPlayer GetPlayerInformation(string login)
		{
			string resource = String.Format("tmf/players/{0}/", login);

			return Execute<TrackManiaPlayer>(resource, WebMethod.Get);
		}

		/// <summary>
		/// Gets the online status of the specified player
		/// </summary>
		/// <param name="login">Player login</param>
		/// <returns>Online status</returns>
		[Obsolete]
		public bool GetPlayerOnlineStatus(string login)
		{
			string resource = String.Format("tmf/players/{0}/online/", login);
			string onlineStatus = Execute<string>(resource, WebMethod.Get);

			return Convert.ToBoolean(onlineStatus);
		}

		/// <summary>
		/// Gets the nickname in HTML format of the specified player
		/// </summary>
		/// <param name="login">Player login</param>
		/// <returns>Nickname HTML</returns>
		public string GetPlayerNicknameHTML(string login)
		{
			string resource = String.Format("tmf/players/{0}/nickname/html/", login);

			return Execute<string>(resource, WebMethod.Get);
		}

		/// <summary>
		/// Gets all the player tags for the specified player
		/// </summary>
		/// <param name="login">Player login</param>
		/// <returns>List of player tags</returns>
		public List<TrackManiaTag> GetPlayerTags(string login)
		{
			string resource = String.Format("tmf/players/{0}/tags/", login);

			return Execute<List<TrackManiaTag>>(resource, WebMethod.Get);
		}

		/// <summary>
		/// Gets the specified players solo ranks
		/// </summary>
		/// <param name="login">Player login</param>
		/// <returns>Ranking information</returns>
		public PlayerRating GetPlayerSoloRankings(string login)
		{
			string resource = String.Format("tmf/players/{0}/rankings/solo/", login);

			return Execute<PlayerRating>(resource, WebMethod.Get);
		}

		/// <summary>
		/// Gets the specified players multiplayer rankings for the specified environment
		/// </summary>
		/// <param name="login">Player login</param>
		/// <param name="environment">Game environment</param>
		/// <returns>Ranking information</returns>
		public PlayerRating GetPlayerMultiplayerRankings(string login, string environment = TrackManiaEnvironments.Merge)
		{
			string resource = String.Format("tmf/players/{0}/rankings/multiplayer/{1}/", login, environment);

			return Execute<PlayerRating>(resource, WebMethod.Get);
		}

		#endregion
	}
}